﻿/// <reference path="VsLib/VsLib.js" />

/// <reference path="jquery-1.8.2.js" />

/// <reference path="../Lib/VsLib/VsLib.js" />
/// <reference path="ServiceMethod.js" />

/// <reference path="../Element/VsIframeProxy/VsIframeProxyClient.js" />
/// <reference path="../Element/VsIframeProxy/VsIframeProxyClientAjax.js" />
/// <reference path="VsMongoRestApiConnection.js" />


(function (context, undefined) {


    function VsPost() {
        $.post.apply(this, arguments);
    }

    function VsPostByIframeProxy() {
        IframeProxyClientAjax.post.apply(IframeProxyClientAjax, arguments);
    }


    var VsSeviceMethod = Class(function () {
        //var ServerURL = 'http://amaps.herokuapp.com';
        //var ServerURL = 'http://172.30.245.176:3000';
        //var ServerURL = 'http://anymap.herokuapp.com';

        var ServerURL = getServiceHost();

        function getServiceHost() {

            var ServiceHost = window.location.protocol + '//' + window.location.host;

            // if (ServiceHost.indexOf('localhost') >= 0)
            {
                ServiceHost = 'http://anymap.herokuapp.com';
            }

            return ServiceHost;
        }

        function getPin(userMapView, userAuthen, callBackFunc)   //UserMapView,User,UserAuth
        {
            var serviceUrl = ServerURL + '/get_pin.json'//'http://damp-lowlands-4129.herokuapp.com/get_pin.json';//'http://localhost:34242/api/eventdataservice';//

            var requestObj = { 'user_map_view': userMapView, 'user_authen': userAuthen };
            //alert(JSON.stringify(requestObj));

            VsPost(serviceUrl, { data: JSON.stringify(requestObj) }, callBackFunc, 'json');

            //HttpRequestPost(serviceUrl, "data: " + JSON.stringify(requestObj), callBackFunc);
            //$.ajax({
            //    url: '',
            //    type: 'POST',
            //    dataType: 'json',
            //});
        }

        function getPinId(userMapView, userAuthen, callBackFunc) {

            var serviceUrl = ServerURL + '/get_pin_id.json';//

            var requestObj = { 'user_map_view': userMapView, 'user_authen': userAuthen };
            //alert(JSON.stringify(requestObj));
            VsPost(serviceUrl, { data: JSON.stringify(requestObj) }, callBackFunc, 'json');

            //getPinIdByRestApi(userMapView, userAuthen, callBackFunc);
        }

        function getPinByIds(pinIds, userAuthen, callBackFunc) {

            var serviceUrl = ServerURL + '/get_pin_by_ids.json';//

            var requestObj = { 'ids': pinIds, 'user_authen': userAuthen };

            var str = JSON.stringify(requestObj);
            // alert(str);

            VsPost(serviceUrl, { data: JSON.stringify(requestObj) }, callBackFunc, 'json');

            //getPinByIdsByRestApi(pinIds, userAuthen, callBackFunc);
        }


        return {

            getPin: function (userMapView, userAuthen, callBackFunc) { getPin(userMapView, userAuthen, callBackFunc); },
            getPinId: function (userMapView, userAuthen, callBackFunc) { getPinId(userMapView, userAuthen, callBackFunc) },
            getPinByIds: function (pinIds, userAuthen, callBackFunc) { getPinByIds(pinIds, userAuthen, callBackFunc) },
      
        };
    });

    if (typeof module !== "undefined" && module.exports) {                       // NodeJS/CommonJS
        module.exports = VsSeviceMethod;
    } else {
        context.VsSeviceMethod = VsSeviceMethod;
    }


}(this));


